//! @Author: DengLibin
//! @Date: Create in 2024-01-04 16:09:02
//! @Description:
//!
use percent_encoding::{percent_decode, utf8_percent_encode};

/// @Author: DengLibin
/// @Date: Create in 2024-01-04 16:12:18
/// @Description: url编码
pub fn url_encode(text: &str) -> String {
    let encoded = utf8_percent_encode(text, percent_encoding::NON_ALPHANUMERIC);
    encoded.to_string()
}

/// @Author: DengLibin
/// @Date: Create in 2024-01-04 16:18:00
/// @Description: url解码
pub fn url_decode(text: &str) -> String {
    // URL解码
    let decoded = percent_decode(text.as_bytes());
    let r = decoded.decode_utf8();
    match r {
        Ok(s) => s.into(),
        Err(e) => e.to_string(),
    }
}
